var file;
var fname;
//图片路径
var imgp = "";
$(function  () {
    var editor = new Simditor({
        textarea: $('#editor'),
        placeholder: '',
        toolbar:  ['title', 'bold', 'italic', 'underline', 'strikethrough', 'fontScale', 'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'hr', '|', 'indent', 'outdent', 'alignment'], //工具条都包含哪些内容
        pasteImage: false,//允许粘贴图片
  });


  var dragImgUpload = new DragImgUpload("#drop_area",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        file = files[0];
        fname = file.name;

        var dataa = new FormData();
        dataa.append('file', file);

        $.ajax({
            url : ipurl+"/upload/add",
            data: dataa,
            contentType: false,
            processData: false,
            type: 'POST',
            success : function(data){
                imgp = data.data+"";
    
            }
        });
    
    }
})  

})

//添加作业
function tt_add(){

    //添加图片

    //标题
    var tt = $("#title").val();
    //内容
    var cc = $("#editor").val();

    //学科Id
    var sid = $.cookie("tsid");
    //用户ID
    var uid = $.cookie("lid");

    $.ajax({
        url : ipurl+"/task/add",
        data: {
            title: tt,
            content: cc,
            imgpath: imgp,
            subId: sid,
            tuid: uid
        },
        type: 'POST',
        success : function(data){
            if(data.success){
                x_admin_close();
                parent.location.reload(); 
            }
        }
    });

}
